package org.dromara.patrol.domain.bo;

import jakarta.validation.Valid;
import org.dromara.common.core.enums.patrol.*;
import org.dromara.common.core.enums.patrol.template.TemplateRuleType;
import org.dromara.patrol.domain.PatrolTask;
import org.dromara.common.mybatis.core.domain.BaseEntity;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import io.github.linpeilie.annotations.AutoMapper;
import lombok.Data;
import lombok.EqualsAndHashCode;
import jakarta.validation.constraints.*;
import org.dromara.patrol.domain.model.ExecuteRule;
import org.dromara.patrol.domain.model.PatrolExecutors;

import java.util.List;

import static org.dromara.common.core.enums.patrol.TaskFinishStatus.TODO;
import static org.dromara.common.core.enums.patrol.TaskType.PATROL;

/**
 * 巡店管理-巡店任务（实时、现场、录像，不包含自检任务）配置业务对象 patrol_task
 *
 * @author Chan
 * @date 2024-03-21
 */
@Data
@EqualsAndHashCode(callSuper = true)
@AutoMapper(target = PatrolTask.class, reverseConvertGenerate = false)
public class PatrolTaskBo extends BaseEntity {

    /**
     * 任务id
     */
    @NotNull(message = "任务id不能为空")
    private Long taskId;
    /**
     * 创建人ID
     */
    private Long creator;
    /**
     * 租户ID
     */
    private String tenantId;

    /**
     * 门店ID集合
     */
    private List<Long> storeIds;

    /**
     * 任务名称
     */
    private String name;

    /**
     * 报告通知人ids
     */
    private String handler;

    /**
     * 创建时间戳
     */
    private Long createdTime;

    /**
     * 巡检任务开始时间（本表字段task_sub_type=PATROL_REALTIME||PATROL_LIVE 必填）
     */
    private Long expectStartTime;

    /**
     * 巡检任务完成时间（本表字段task_sub_type=PATROL_REALTIME|| PATROL_LIVE必填）
     */
    private Long expectFinishTime;

    /**
     * 任务状态（字典表：PROCESSING 执行中，TODO 待处理，FINISH 已完成）
     * @see org.dromara.common.core.enums.patrol.TaskFinishStatus
     */
    private TaskFinishStatus status = TODO;

    /**
     * 任务类型（字典表：PATROL 巡店，SELF_CHECK自检）
     * @see org.dromara.common.core.enums.patrol.TaskType
     */
    private TaskType taskType = PATROL;

    /**
     * 巡店方式类型（字典表：PATROL_REALTIME 实时巡店，PATROL_LIVE 现场巡店，PATROL_VIDEO 录像巡店，SELF_CHECK 门店自检）
     * @see org.dromara.common.core.enums.patrol.TaskSubType
     */
    @NotNull(message = "巡店方式类型（字典表：PATROL_REALTIME 实时巡店，PATROL_LIVE 现场巡店，PATROL_VIDEO 录像巡店，SELF_CHECK 门店自检）不能为空", groups = { AddGroup.class, EditGroup.class })
    @Valid
    private TaskSubType taskSubType;

    /**
     * 巡店模式（字典表：PATROL_TEMPLATE 模板巡店，PATROL_USER_DEFINED 自定义巡店）
     * @see org.dromara.common.core.enums.patrol.PatrolSubType
     */
    @NotNull(message = "巡店模式（字典表：PATROL_TEMPLATE 模板巡店，PATROL_USER_DEFINED 自定义巡店 不能为空", groups = { AddGroup.class, EditGroup.class })
    @Valid
    private PatrolSubType patrolSubType;

    /**
     * 巡店模板id（）
     */
    private Long templateId;

    /**
     * 备注
     */
    private String remark;

    /**
     * 录像巡店开始时间（本表字段task_sub_type=PATROL_VIDEO 必填）
     */
    private Long videoStartTime;

    /**
     * 录像巡店结束时间（本表字段task_sub_type=PATROL_VIDEO 必填）
     */
    private Long videoEndTime;

    /**
     * 重复类型（字典表：NO_REPEAT 不重复，DAILY 每天，WEEKLY 每周，MONTHLY 每月）
     */
    private RepeatType cycleType;

    /**
     * 模板规则（字典表：COMMON 使用统一模板，CUSTOMIZE 自主选择模板）
     */
    @NotNull(message = "模板规则（字典表：COMMON 使用统一模板，CUSTOMIZE 自主选择模板）不能为空", groups = { AddGroup.class, EditGroup.class })
    @Valid
    private TemplateRuleType templateRule;

    /**
     * 执行规则{
        "cycleType": "NO_REPEAT",
        "weeklyRule": null,
        "monthlyRule": null,
        "executeDateStart": "2024-03-11",
        "executeDateEnd": "2024-03-12",
        "executeTimeStart": "00:00:00",
        "executeTimeEnd": "23:59:59"
    }
     */
    @NotNull(message = "执行规则不能为空", groups = { AddGroup.class, EditGroup.class })
    @Valid
    private ExecuteRule executeRule;

    /**
     * 巡检门店id、人员相关json[
        {
            "storeId": "6636b81c-d561-11ee-b4bb-1dbe6922f4cd",
            "storeName": null,
            "executors": [
                {
                    "executor": "cd9729fc-d79c-11ee-b05d-83ebc9b829a7",
                    "executorName": null
                }
            ],
            "departmentId": null,
            "departmentName": null,
            "roleId": null,
            "roleName": null
        }
    ]
     */
    @NotEmpty(message = "巡检门店id、人员相关json不能为空", groups = { AddGroup.class, EditGroup.class })
    @Valid
    private List<PatrolExecutors> patrolExecutors;

    /**
     * 通知人
     */
    private List<Long> notifierIds;

    /**
     * 版本
     */
    private String ver;
}
